Repository navigation
feat(nav3): [Part 10] Use built-in BackStackEntryMappers in the Nav3 sample app - #6707
Open
0xadam-brown wants to merge 2 commits into
Open
0xadam-brown wants to merge 2 commits into
0xadam-brown wants to merge 2 commits into
Conversation
This was referenced Nov 20, 2026
Contributor
|
Contributor
PR risk: mediumFor commit The model rated this change low. It was raised to medium because:
This label is a hint for reviewers, not an approval. |
5 of 9 tasks
4 of 9 tasks
📲 Install BuildsAndroid
|
0xadam-brown
force-pushed
the
feat/nav3-serial-name-mappers-10
branch
from
November 20, 2026 14:00
7a34760 to
f7b850a
Compare
0xadam-brown
marked this pull request as ready for review
November 20, 2026 15:51
0xadam-brown
requested review from
markushi and
runningcode
and removed request for
a team
November 20, 2026 15:51
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Stack (Nav3 Serial Name Mappers)
📜 Description
PR updates the Nav3 sample app to make use of the new built-in
BackStackEntryMappers.PR also extends the sample app's Performance tab to allow for performance testing against the new mappers.
💡 Motivation and Context
The performance scenario needs to distinguish the cost of real built-in mapping from synthetic name and argument workloads. It therefore keeps the custom performance mapper and adds a choice to exercise the built-in mapper itself, so measurements can reflect the path an application would actually use.
addresses: JAVA-787 (link)
No performance or related issues identified in connection withthis PR stack.
I had my clankers do some deep dives w/r/t whether this PR stack introduces any performance issues, memory leaks, or opportunities to crash the host app. No issues were found. Here's a summary:
Performance
JVM microbenchmark
Measured on the JVM through the real
BackStackConverter: 5 entries per update (the default capture size), each with 7 properties including a list, a map, and a sensitive key. Warmup 20k iterations, timed over 50k.SerialName(names only)SerialNameAndPropertiesSerialNameAndProperties, serializer throws every updateOn-device confirmation (emulator, API 36)
Ran the Nav3 sample's stress scenario with a new Mapper toggle (Custom vs
SerialNameAndProperties), Normal preset (back stack depth 20, capture 20), 20 measured iterations per run. Numbers are the published diagnostics read from logcat.Fixed runs — mutation → composition p50:
SerialNameAndPropertiesA/B comparison (integration disabled vs full stack) — first-draw p50:
SerialNameAndPropertiesThe built-in mapper tracks the custom mapper within run-to-run noise on every run, including the "top stays put" lower-mutation run. The whole integration's on-device cost — encoding included — is sub-millisecond per update at the frame level, consistent with the ~10 µs JVM figure being lost against a ~16–33 ms Compose frame. Emulator numbers; a low-end physical device is slower in absolute terms, but the custom-vs-built-in gap being within noise should hold since both walk the same sanitizer pipeline.
mainalready re-converted entries on every observed stack change, including when the top is unchanged. The branch adds serializer calls into that loop forSerialNameAndProperties. Value/text/depth limits already existed.SerializationExceptions per type to stop the retries.TreeArgumentWriter+IdentityHashMap+ container stacks per entry with arguments (previously one identity map per update). Didn't register at this size. Optional: allocate the identity map lazily on first container.SensitiveKeyFilterre-checks as a safeguard). Bounded by the budget; didn't register at this size.Conclusion: No performance issue that warrants a design change before merge. The on-device run confirmed the built-in mapper is within noise of a custom mapper, including rapid stack changes where the top stays put, so the duplicate denylist scan and per-entry identity tracking don't need changing.
Memory
ConcurrentHashMaps keyed byClassholding each route type's name, serializer, "has properties" flag, and which warnings were already loggedvals)KotlinxArgumentsmapKSerializer, theonFailurecallback, and the lazily encoded copyBackStackObserverstores only the sanitized plain-map output and aWeakReferenceto the previous top entry. The route is only held longer if the host keeps the mapper's result, and the host already holds its own back stack key. KDoc now states this (commit408281228a).TreeArgumentWriterwith itsIdentityHashMapand container/identity stacksScopesAdapter.getInstance().options.loggerNavigationcontext (persisted to disk on Android each update)main. The change is thatSerialNameAndPropertiessends arguments by default, so more apps populate these. Still capped by the shared per-update budget (200 values / 4,096 characters). Custom mappers with arguments already behaved this way.Conclusion: No new memory leak. The Activity watcher, lifecycle disposal, and the
WeakReferenceto the previous top entry all predate the branch and were re-checked.Crashing the host app
SerialName/SerialNameAndProperties)create()catchesLinkageError(missing/incompatible kotlinx, ART verification failure of theAbstractEncodersubclass,ExceptionInInitializerError); the compatibility probe catches all other non-fatal errors and reports them as inconclusivemap()LinkageErrorand other non-fatal throwables are caught and cached per type as/unknownmap()directly (as the sample does).KotlinxArguments, encoder)LinkageError; serializer misuse (e.g. an unbalancedendStructure()) surfaces asencoding_failed; the one internalcheck()is unreachable from host pathsMAX_SERIALIZER_NESTING(64) andMAX_ARGUMENT_DEPTH(10) — roughly ~1,000 frames, well within the main-thread stackStackOverflowErrorfollows AGENTS.md's fatal-error policy.ExceptionUtils.rethrowIfFatalis applied before every broad catchOutOfMemoryError,StackOverflowError,LinkageError(where fatal), etc. are rethrown by designConclusion: No new way to crash the host under normal operation. The only non-fatal escape is a throwing host logger, which is a pre-existing SDK-wide behavior; the one new call site worth noting is mapper creation during composition. Optional hardening: wrap the diagnostic calls in the mapper constructor.
💚 How did you test it?
Nav3 release build and all 872 unit tests passed. Repository-wide
make format api, Spotless checks, ABI validation, and Detekt passed. The Android sample debug build passed after including its shared serialization-plugin setup in this slice.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Continue with PR 11: Verify mapping after R8 minification.
#skip-changelog